#ifndef PROJITEM
#define PROJITEM
#include "commoninc.h"
#include "exttool.h"
class ProjItem;
class CMimeData;
class ProjGroup;

class CMimeData : public QMimeData {
    Q_OBJECT

public:
    void setParentWidget(ProjGroup *p) { _parentWidget = p; }
    ProjGroup *parentWidget() { return _parentWidget; }

    void setThisWidget(ProjItem *p) { _thisWidget = p; }
    ProjItem *thisWidget() { return _thisWidget; }

private:
    ProjGroup *_parentWidget;
    ProjItem *_thisWidget;
};

class ProjGroup : public QFrame {
    Q_OBJECT
public:
    ProjGroup(QWidget *p);
    ~ProjGroup();

public:
    void setGroupName(const QString &name) { _groupNameEdit->setText(name); }
    QJsonObject getJsonData();

private:
    void initUI();
    void initItemList();

public:
    void addProjItem(const QString &path);

private slots:
    void addNewProjItem();
    void addDropProjEvt(const QMimeData *data);
    void deleteItem(ProjItem *);

Q_SIGNALS:
    void removeGroup(ProjGroup *);

protected:
    void dragEnterEvent(QDragEnterEvent *event);
    void dropEvent(QDropEvent *event);

private:
    QLineEdit *_groupNameEdit;
    QPushButton *_rmBtn;
    QGridLayout *_itemGdLay;
    ProjItem *_addProjBtn;
    QList<ProjItem*> _itemList;
};

class ProjItem : public QToolButton {
    Q_OBJECT
public:
    ProjItem(QWidget *p = nullptr);
    ~ProjItem();

    void setProjUrl(QString url);
    QString projUrl() { return _projUrl; }
    QJsonObject getJsonData();

Q_SIGNALS:
    void deleteItem(ProjItem *);

private slots:
    void runProj();

private:
    void initUI();
    void initMenu();

    bool isImage(const QString &file);

protected:
    void mousePressEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);

private:
    QString _projUrl;
    QMenu *_itemMenu;
    QAction *_openItem;
    QAction *_deleteItem;
    QAction *_infoItem;

    bool _isPressed;
    bool _isDraged;
    QPoint _pressedPos;
};

#endif // PROJITEM

